/**
 * 
 */
package note;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.ListModel;

/**
 * @author haiyuzha
 *
 */
class ListMenu extends JList implements MouseListener {
	private JPopupMenu popupMenu = null;
	private JMenuItem newItem = null;
	private JMenuItem deleteItem = null;
	private JMenuItem sortItem = null;
	/**
	 * 
	 */
	public ListMenu() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param dataModel
	 */
	public ListMenu(ListModel dataModel) {
		super(dataModel);

		addMouseListener(this);
		
		popupMenu = new JPopupMenu();
		popupMenu.add(newItem = new JMenuItem("New"));
		popupMenu.add(deleteItem = new JMenuItem("Delete"));
		popupMenu.add(sortItem = new JMenuItem("Sort"));
		//popupMenu.add(sortItem = new JMenuItem("Sort"));
		
		add(popupMenu);
	}

	/**
	 * @param listData
	 */
	public ListMenu(Object[] listData) {
		super(listData);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param listData
	 */
	public ListMenu(Vector<?> listData) {
		super(listData);
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
	 */
	@Override
	public void mousePressed(MouseEvent e) {
		if (e.getButton() == MouseEvent.BUTTON3) {
			newItem.setEnabled(!this.isSelectionEmpty());
			deleteItem.setEnabled(!this.isSelectionEmpty());
			sortItem.setEnabled(!this.isSelectionEmpty());
			popupMenu.show(this, e.getX(), e.getY());
		}
	}

	/* (non-Javadoc)
	 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
